package com.dcivision.framework.taglib.html;

import javax.servlet.jsp.JspException;

import com.dcivision.framework.Utility;
/**
 * for dymatic textarea 
 * example <html:dytextarea styleClass="normal-style" miniStyleClass="mini-style" property="description"/>
 * when this tag 's value is empty,show mini-style,and when click this tag,it show normal-style.
 * when this tag onblur,if it's value is empty,show mini-style.
 * @author tc tang
 *
 */
public class DynamicTextareaTag extends TextareaTag {

  private String miniStyleClass = "form-style-2-mini-textarea";
  
  public int doStartTag() throws JspException {
    
     String styleClass = getStyleClass();
     
     if(Utility.isEmpty(super.renderData())){
       //is text area is empty,select small style
       super.setStyleClass(miniStyleClass);
     }
     
      String originalOnClick = super.getOnclick();
      originalOnClick = (originalOnClick==null) ? "" : originalOnClick;
      super.setOnclick("enlargeTextareaSize(this,'"+styleClass+"');"+originalOnClick);
      String originalOnblur = super.getOnblur();
      originalOnblur = (originalOnblur==null) ? "" : originalOnblur;
      super.setOnblur("miniTextareaSize(this,'"+this.getMiniStyleClass()+"');"+originalOnblur);
      return super.doStartTag();
  }
  
  public int doEndTag() throws JspException {
    int result = super.doEndTag();
    this.release();
    return(result);
  }
  
  public void release() {
    super.release();
    this.miniStyleClass = "form-style-2-mini-textarea";
  }

  public String getMiniStyleClass() {
    return miniStyleClass;
  }

  public void setMiniStyleClass(String miniStyleClass) {
    this.miniStyleClass = miniStyleClass;
  }

 
  
}
